home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD15883342001.psc / File Transfer / frmClient.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2001-02-04  |  14.5 KB  |  369 lines

  1. VERSION 5.00
  2. Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
  3. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  4. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  5. Begin VB.Form frmClient 
  6.    BorderStyle     =   1  'Fixed Single
  7.    Caption         =   "Client"
  8.    ClientHeight    =   8190
  9.    ClientLeft      =   45
  10.    ClientTop       =   330
  11.    ClientWidth     =   7095
  12.    LinkTopic       =   "Form3"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   8190
  16.    ScaleWidth      =   7095
  17.    StartUpPosition =   3  'Windows Default
  18.    Begin VB.TextBox txtChat 
  19.       Height          =   1575
  20.       Left            =   120
  21.       Locked          =   -1  'True
  22.       MultiLine       =   -1  'True
  23.       ScrollBars      =   2  'Vertical
  24.       TabIndex        =   12
  25.       Top             =   6120
  26.       Width           =   6855
  27.    End
  28.    Begin VB.TextBox txtSend 
  29.       Height          =   285
  30.       Left            =   120
  31.       TabIndex        =   11
  32.       Top             =   7800
  33.       Width           =   5535
  34.    End
  35.    Begin VB.CommandButton cmdSendChat 
  36.       Caption         =   "Send Chat"
  37.       Default         =   -1  'True
  38.       Height          =   255
  39.       Left            =   5760
  40.       TabIndex        =   10
  41.       Top             =   7800
  42.       Width           =   1215
  43.    End
  44.    Begin VB.Timer tmrKBps 
  45.       Interval        =   1000
  46.       Left            =   0
  47.       Top             =   8400
  48.    End
  49.    Begin VB.CommandButton cmdSend 
  50.       Caption         =   "&Send File"
  51.       Height          =   495
  52.       Left            =   5520
  53.       TabIndex        =   6
  54.       Top             =   3960
  55.       Width           =   1215
  56.    End
  57.    Begin VB.DriveListBox lstDrive 
  58.       Height          =   315
  59.       Left            =   120
  60.       TabIndex        =   5
  61.       Top             =   360
  62.       Width           =   3135
  63.    End
  64.    Begin VB.DirListBox lstDir 
  65.       Height          =   1665
  66.       Left            =   120
  67.       TabIndex        =   4
  68.       Top             =   720
  69.       Width           =   3135
  70.    End
  71.    Begin VB.FileListBox lstFiles 
  72.       Height          =   1455
  73.       Left            =   120
  74.       System          =   -1  'True
  75.       TabIndex        =   3
  76.       Top             =   2400
  77.       Width           =   3135
  78.    End
  79.    Begin VB.CommandButton cmdAddFile 
  80.       Caption         =   "&Add File"
  81.       Height          =   495
  82.       Left            =   1080
  83.       TabIndex        =   2
  84.       Top             =   3960
  85.       Width           =   1215
  86.    End
  87.    Begin VB.ListBox lstSend 
  88.       Height          =   3375
  89.       Left            =   3720
  90.       TabIndex        =   1
  91.       Top             =   360
  92.       Width           =   3255
  93.    End
  94.    Begin VB.CommandButton cmdRemove 
  95.       Caption         =   "&Remove File"
  96.       Height          =   495
  97.       Left            =   3960
  98.       TabIndex        =   0
  99.       Top             =   3960
  100.       Width           =   1215
  101.    End
  102.    Begin MSComDlg.CommonDialog CD 
  103.       Left            =   120
  104.       Top             =   8160
  105.       _ExtentX        =   847
  106.       _ExtentY        =   847
  107.       _Version        =   393216
  108.    End
  109.    Begin MSWinsockLib.Winsock Winsock 
  110.       Left            =   0
  111.       Top             =   8760
  112.       _ExtentX        =   741
  113.       _ExtentY        =   741
  114.       _Version        =   393216
  115.    End
  116.    Begin VB.ListBox lstPath 
  117.       Height          =   3375
  118.       Left            =   3720
  119.       TabIndex        =   7
  120.       Top             =   360
  121.       Width           =   3255
  122.    End
  123.    Begin MSComctlLib.ProgressBar PBar 
  124.       Height          =   735
  125.       Left            =   240
  126.       TabIndex        =   13
  127.       Top             =   4800
  128.       Width           =   6615
  129.       _ExtentX        =   11668
  130.       _ExtentY        =   1296
  131.       _Version        =   393216
  132.       Appearance      =   1
  133.       Scrolling       =   1
  134.    End
  135.    Begin VB.Label lblKBps 
  136.       Alignment       =   2  'Center
  137.       Caption         =   "KBps:"
  138.       Height          =   255
  139.       Left            =   1200
  140.       TabIndex        =   14
  141.       Top             =   5640
  142.       Width           =   4455
  143.    End
  144.    Begin VB.Line Line1 
  145.       X1              =   120
  146.       X2              =   6960
  147.       Y1              =   4560
  148.       Y2              =   4560
  149.    End
  150.    Begin VB.Line Line2 
  151.       X1              =   3480
  152.       X2              =   3480
  153.       Y1              =   120
  154.       Y2              =   4560
  155.    End
  156.    Begin VB.Label Label1 
  157.       Alignment       =   2  'Center
  158.       Caption         =   "Select Files"
  159.       BeginProperty Font 
  160.          Name            =   "MS Sans Serif"
  161.          Size            =   13.5
  162.          Charset         =   0
  163.          Weight          =   400
  164.          Underline       =   0   'False
  165.          Italic          =   0   'False
  166.          Strikethrough   =   0   'False
  167.       EndProperty
  168.       Height          =   375
  169.       Left            =   240
  170.       TabIndex        =   9
  171.       Top             =   0
  172.       Width           =   2775
  173.    End
  174.    Begin VB.Label Label2 
  175.       Alignment       =   2  'Center
  176.       Caption         =   "Send Files"
  177.       BeginProperty Font 
  178.          Name            =   "MS Sans Serif"
  179.          Size            =   13.5
  180.          Charset         =   0
  181.          Weight          =   400
  182.          Underline       =   0   'False
  183.          Italic          =   0   'False
  184.          Strikethrough   =   0   'False
  185.       EndProperty
  186.       Height          =   375
  187.       Left            =   3960
  188.       TabIndex        =   8
  189.       Top             =   0
  190.       Width           =   2775
  191.    End
  192. Attribute VB_Name = "frmClient"
  193. Attribute VB_GlobalNameSpace = False
  194. Attribute VB_Creatable = False
  195. Attribute VB_PredeclaredId = True
  196. Attribute VB_Exposed = False
  197. Option Explicit
  198. Dim strFriend As String 'holds servers name
  199. Dim strMyName As String 'holds your name
  200. Dim strFileName As String 'holds the name of the file u are receiving
  201. Dim strSize As String 'holds the size of the file
  202. Dim strSoFar As String 'a var for calculating the KBps
  203. Dim strBlock As String 'holds the data you are going to send
  204. Dim strLOF As String 'holds the lenght of the file
  205. Private Sub cmdAddFile_Click()
  206.     If lstFiles.ListIndex = -1 Then 'if nothing is selected
  207.         MsgBox "Please select a file, then click Add File", vbInformation, "Add File"
  208.     Else
  209.         lstSend.AddItem lstFiles.List(lstFiles.ListIndex)
  210.         lstPath.AddItem lstDir.Path
  211.     End If
  212. End Sub
  213. Private Sub cmdRemove_Click()
  214.     If lstSend.ListIndex = -1 Then 'if nothing is selected
  215.         MsgBox "Please select a file to remove, and then hit remove.", vbInformation, "Remove File"
  216.     Else
  217.         lstPath.RemoveItem lstSend.ListIndex
  218.         lstSend.RemoveItem lstSend.ListIndex
  219.     End If
  220. End Sub
  221. Private Sub cmdSendChat_Click()
  222.     If Trim(txtSend.Text) = "" Then Exit Sub 'prevents someone trying to send nothing
  223.     Winsock.SendData "Chat" & txtSend.Text 'sends the text to the chat
  224.     txtChat.SelStart = Len(txtChat) 'put focus on the chat at the end so it is entered in the right place
  225.     txtChat.SelText = strMyName & ":" & vbTab & txtSend.Text & vbCrLf 'puts the text in the chat
  226.     txtSend.Text = "" 'clears the textbox u type in
  227. End Sub
  228. Private Sub Form_Unload(Cancel As Integer)
  229.     Winsock.Close 'closes winsock so program can end
  230.     End 'closes program
  231. End Sub
  232. Private Sub lstDir_Change()
  233.     lstFiles.Path = lstDir.Path 'links them together
  234. End Sub
  235. Private Sub lstDrive_Change()
  236. On Error GoTo driveError 'if A: drive isnt ready (forexample)
  237.     lstDir.Path = lstDrive.Drive
  238.     Exit Sub
  239. driveError:
  240.     MsgBox "The current device is unavailable", vbCritical, "Error"
  241.     lstDrive.ListIndex = 1 'goes to C:
  242. End Sub
  243. Private Sub tmrKBps_Timer()
  244. On Error Resume Next 'prevents error
  245.     lblKBps.Caption = "Transfering at: " & Format(strSoFar / 1000, "###0.0") & " / KBps" 'calculates the KBps
  246.     strSoFar = 0 'resets it so it can be calculated again
  247. End Sub
  248. Private Sub Winsock_Connect()
  249.     frmConnect.tmrClient.Enabled = False 'tell client to stop trying to connect cause it is connected =D
  250.     Winsock.SendData "Nick" & frmConnect.txtName.Text 'sends ur name to server
  251.     DoEvents 'i dunno why but i need it cause of winsock
  252.     strMyName = frmConnect.txtName 'saves ur name into memory
  253.     Me.Show 'shows frmclient
  254.     Unload frmConnect 'obvious
  255. End Sub
  256. Private Sub cmdSend_Click()
  257. On Error Resume Next 'prevents error
  258.     strFileName = "" 'resets the filename
  259.     strSize = "" 'resets the size
  260. Dim intX As Integer
  261. Dim strFile, strPath As String
  262.         strFile = lstSend.List(0)
  263.         strPath = lstPath.List(0)
  264.         lstSend.RemoveItem 0
  265.         lstPath.RemoveItem 0
  266.         Open strPath & "\" & strFile For Binary As #1 'opens the file to be sent and reads it
  267.         strLOF = LOF(1) 'gets the length of the file
  268.         Winsock.SendData "Name" & strFile & ":" & strLOF 'sends the name of the first file and its length
  269. End Sub
  270.             
  271. Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
  272. On Error Resume Next 'prevents error
  273. Dim strData As String 'holds data for select case
  274. Dim strData2 As String 'holds data
  275.     Call Winsock.GetData(strData, vbString) 'gets the data sent by the server
  276.     strData2 = Mid(strData, 5) 'gets data
  277.     strData = Left(strData, 4) 'gets data for select case
  278.     Select Case strData 'goes to the right case depending on strData
  279.         Case "File" 'a file transfer is in progress
  280.             Put 1, , strData2 'puts data into file
  281.             PBar.Value = PBar.Value + bytesTotal 'shows how much is done so far
  282.             strSoFar = strSoFar + bytesTotal 'calculates KBps
  283.             If Not LOF(1) >= PBar.Max Then
  284.                 Winsock.SendData "OKOK keep sending!" 'tells them ur done with the data and u want some more!
  285.                 DoEvents ' =D
  286.             End If
  287.         Case "Name" 'client has sent u the filename and is ready to begin transfer
  288.             Dim intX As Integer 'holds position if :
  289.             intX = InStr(1, strData2, ":", vbTextCompare) 'gets position of :
  290.             strSize = Mid(strData2, intX + 1) 'holds the filesize
  291.             PBar.Max = strSize 'sets up the progressbar
  292.             strData = Mid(strData2, 1, intX - 1) 'holds filename
  293.             strFileName = strData 'puts filename into memory
  294.             Dim strResponse As String 'holds either a vbYEs or vbNo
  295.             strResponse = MsgBox(strFriend & " wants to send you [" & strFileName & "].  Do you wish to receive this file?", vbYesNo, "File Exchange Requested") '<=- easy to understand
  296.             If strResponse = vbYes Then 'if they said yes
  297.                 Dim strType As String 'holds the type of file
  298.                 strType = Right(strFileName, 3) 'gets the type of file
  299.                 CD.FileName = strFileName 'sets the filename into the commondialog box
  300.                 CD.Filter = "File Type (*." & strType & ")|*." & strType 'sets the filter to the filetype
  301.                 CD.Flags = cdlOFNOverwritePrompt 'asks u if u want to overwrite file
  302.                 CD.ShowSave 'shows the save commondialog box
  303.                 Open CD.FileName For Binary As #1 'opens a file with the name and path u want
  304.                 Winsock.SendData "OKOK i want the file" 'tell client u want the damn file
  305.                 Me.Enabled = False 'disables to form to PREVENT ERROR!!!!!!!!!!
  306.             ElseIf strResponse = vbNo Then 'if they say no
  307.                 Winsock.SendData "Nope dont want it!" 'tell em u dont want their crap!
  308.                 DoEvents 'hmmm
  309.             End If 'ok enough of that madness
  310.         Case "Stop" 'the file exchange has ended
  311.             Close #1 'closes the file
  312.             'resets the progressbar
  313.             PBar.Value = 0
  314.             PBar.Max = 1
  315.             '=====================
  316.             Me.Enabled = True 'reenables the form!
  317.             DoEvents
  318.             Winsock.SendData "OKOKmore"
  319.         Case "Nick" 'client has sent u their name
  320.             strFriend = strData2 'saves their name into memory
  321.         Case "Nope" 'tells u that they declined ur request to give em a file
  322.             MsgBox strFriend & " declined your file transfer request.", vbInformation, "File Transfer Canceled!" '<=- easy to get again
  323.             Close #1 'closes the file
  324.             'stops the loops that was waiting for the boolean value to be true
  325.             Do
  326.             DoEvents
  327.             Loop
  328.             '==========================
  329.         Case "OKOK" 'tells u they want more of the file
  330.             If strData2 = "more" Then
  331.                 If lstSend.ListCount <> 0 Then
  332.                     cmdSend_Click
  333.                     Exit Sub
  334.                 Else
  335.                     Exit Sub
  336.                 End If
  337.             End If
  338.             Me.Enabled = False 'keeps form disabled
  339.             PBar.Max = strLOF 'sets progressbar max to filesize
  340.             If Not EOF(1) Then 'does this if not the end of the file
  341.                 If strLOF - Loc(1) < 2040 Then 'if you are at the last chunk of data
  342.                     strBlock = Space$(strLOF - Loc(1)) 'sets the block size to the size of the data (cause its less!)
  343.                     Get 1, , strBlock 'gets data
  344.                     Winsock.SendData "File" & strBlock 'sends data
  345.                     DoEvents ' =/
  346.                     PBar.Value = PBar.Value + Len(strBlock) 'sets progressbar
  347.                     strSoFar = strSoFar + (strLOF - Loc(1)) 'sets KBps
  348.                     Winsock.SendData "Stop the maddness!" 'tells client THE TRANSFER IS ENDED!
  349.                     Close #1 'closes file
  350.                     'resets the progressbar
  351.                     PBar.Max = 1
  352.                     PBar.Value = 0
  353.                     '====================
  354.                     Me.Enabled = True 'reenables the form
  355.                 Else 'if not the last chunk
  356.                     strBlock = Space$(2040) 'sets block up to receive only 2040 bytes of data
  357.                 End If
  358.                 strSoFar = strSoFar + 2040 'calculates KBps
  359.                 Get 1, , strBlock 'gets data
  360.                 Winsock.SendData "File" & strBlock 'sends data
  361.                 DoEvents
  362.                 PBar.Value = PBar.Value + Len(strBlock) 'sets progressbar
  363.             End If
  364.         Case "Chat" 'if they are talking to ya
  365.             txtChat.SelStart = Len(txtChat) 'sets cursor position in chatroom
  366.             txtChat.SelText = strFriend & ":" & vbTab & strData2 & vbCrLf 'puts the chat into the room
  367.     End Select
  368. End Sub
  369.